package com.xj.util;

import freemarker.template.*;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import java.io.*;
import java.nio.charset.StandardCharsets;

/**
 * @author ricky
 * @date 2022/9/14
 */
@Slf4j
public class FreemakerUtil {

    private FreemakerUtil() {
    }

    private static final Configuration CFG;

    static {
        CFG = new Configuration(Configuration.VERSION_2_3_22);
        CFG.setDefaultEncoding("UTF-8");
        CFG.setClassForTemplateLoading(FreemakerUtil.class, "/templates");
        CFG.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    }

    public static Template getTemplate(String filename) throws IOException {
        return CFG.getTemplate(filename);
    }
}
